package CutLoad.cookies
{
	import flash.utils.Dictionary;  
	public class CHashMap
	{
		private var _keys:Array = null;  
		private var props:Dictionary = null; 
			public function CHashMap(){  
				this.clear();  
			}  
			/**
			 * 清空 
			 * 
			 */			
			public function clear():void{  
				this.props = new Dictionary();  
				this._keys = new Array();  
			}  
			/**
			 * 是否包括这个键
			 * @param key 键值
			 * @return 
			 * 
			 */			
			public function containsKey(key:Object):Boolean{  
				return this.props[key] != null;  
			}  
			/**
			 * 是否包括这个值 
			 * @param value
			 * @return 
			 * 
			 */			
			public function containsValue(value:Object):Boolean{  
				var result:Boolean = false;  
				var len:uint = this.size();  
				if(len > 0){  
					for(var i:uint = 0 ; i < len ; i++){  
						if(this.props[this._keys[i]] == value) return true;  
					}  
				}  
				return false;
			}  
			/**
			 * 获得一个值 
			 * @param key
			 * @return 
			 * 
			 */			
			public function get(key:Object):Object{  
				return this.props[key];  
			}  
			/**
			 * 添加值 
			 * @param key
			 * @param value
			 * @return 
			 * 
			 */			
			public function put(key:Object,value:Object):Object{  
				var result:Object = null;  
				if(this.containsKey(key)){  
					result = this.get(key);  
					this.props[key] = value;  
				}else{  
					this.props[key] = value;  
					this._keys.push(key);  
				}  
				return result;  
			}  
			/**
			 * 去除一个值 
			 * @param key
			 * @return 
			 * 
			 */			
			public function remove(key:Object):Object{  
				var result:Object = null;  
				if(this.containsKey(key)){  
					delete this.props[key];  
					var index:int = this._keys.indexOf(key);  
					if(index > -1){  
						this._keys.splice(index,1);  
					}  
				}  
				return result;  
			}  
			/**
			 * 把 CHashMap数据添加进去
			 * @param map
			 * 
			 */			
			public function putAll(map:CHashMap):void{  
				this.clear();  
				var len:uint = map.size();  
				if(len > 0){  
					var arr:Array = map.keys;  
					for(var i:uint=0;i<len;i++){  
						this.put(arr[i],map.get(arr[i]));  
					}  
				}  
			}  
			/**
			 * 长度 
			 * @return 
			 * 
			 */			
			public function size():uint{  
				return this._keys.length;  
			}  
			/**
			 * 是否空 
			 * @return 
			 * 
			 */			
			public function isEmpty():Boolean{  
				return this.size() < 1;  
			}  
			/**
			 * 转换成数组 
			 * @return 
			 * 
			 */			
			public function values():Array{  
				var result:Array = new Array();  
				var len:uint = this.size();  
				if(len > 0){  
					for(var i:uint = 0;i<len;i++){  
						result.push(this.props[this._keys[i]]);  
					}  
				}  
				return result;  
			}  
			/**
			 * 返回含用键值的数组 
			 * @return 
			 * 
			 */			
			public function get keys():Array{  
				return this._keys;  
			}  
		}  
	}
